/**
 * @file   1105.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sun May  9 17:37:38 2021
 * 
 * @brief  PAT 1105
 * 
 * 
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int N;
    cin>>N;
    int d=sqrt(N);
    int row,column;
    for(int i=d;i>=1;i--){
	if(N%i==0){
	    column=i;
	    row=N/i;
	    break;
	}
    }
    vector<vector<int>> SMatrix;
    SMatrix.resize(row);
    for(int i=0;i<row;i++){
	SMatrix[i].resize(column);
    }
    int option=0;//0:right,1:down,2:left,3:up
    int rowindex=0;
    int columnindex=0;
    vector<int> input;
    for(int i=0;i<N;i++){
	int d;
	cin>>d;
	input.push_back(d);
    }
    sort(input.begin(),input.end(),cmp);
    for(int i=0;i<N;i++){
	bool add=false;
	while(add==false){
	    switch(option){
	    case 0:
		if(columnindex==column||SMatrix[rowindex][columnindex]!=0){
		    option=(option+1)%4;
		    columnindex--;//Backtrack
		    rowindex++;
		}else{
		    SMatrix[rowindex][columnindex++]=input[i];
		    add=true;
		}
		break;
	    case 1:
		if(rowindex==row||SMatrix[rowindex][columnindex]!=0){
		    option=(option+1)%4;
		    rowindex--;
		    columnindex--;
		}else{
		    SMatrix[rowindex++][columnindex]=input[i];
		    add=true;
		}
		break;
	    case 2:
		if(columnindex==-1||SMatrix[rowindex][columnindex]!=0){
		    option=(option+1)%4;
		    columnindex++;
		    rowindex--;
		}else{
		    SMatrix[rowindex][columnindex--]=input[i];
		    add=true;
		}
		break;
	    case 3:
		if(rowindex==-1||SMatrix[rowindex][columnindex]!=0){
		    option=(option+1)%4;
		    rowindex++;
		    columnindex++;
		}else{
		    SMatrix[rowindex--][columnindex]=input[i];
		    add=true;
		}
		break;
	    }	    
	}
    }
    for(int i=0;i<row;i++){
	cout<<SMatrix[i][0];
	for(int j=1;j<column;j++){
	    cout<<" "<<SMatrix[i][j];
	}
	cout<<endl;
    }
}
